package com.zw.pm.config;

import com.zw.pm.util.ServletUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @Description: 全局异常处理器
 *
 * @Author: China.sgl
 * @Date: 2019/9/18 08:59
 */
@ControllerAdvice
@Slf4j
public class GlobalExceptionHandler {

    @ExceptionHandler(Exception.class)
    public String allExceptionHandler(HttpServletRequest request, HttpServletResponse response) {
        if (ServletUtils.isAjaxRequest(request)) {
            return ServletUtils.renderString(response, "{\"type\":\"ERROR\",\"msg\":\"系统错误，请联系管理员！\"}");
        }
        return "/500";
    }

}
